#include "stdafx.h"
#include "GAnimation.h"

GAnimation::GAnimation()
{
	CurrentFrame = 0;
	MaxFrames = 0;
	FrameInc = 1;

	FrameRate       = 100; //Milliseconds
	OldTime         = 0;

	Oscillate       = false;
}

GAnimation::~GAnimation()
{
}

void GAnimation::OnAnimate()
{
	if(OldTime + FrameRate > SDL_GetTicks())
	{
		return;
	}

	OldTime = SDL_GetTicks();

	CurrentFrame += FrameInc;

	if(Oscillate)
	{
		//if(FrameInc > 0)
		//{
			if(CurrentFrame >= MaxFrames)
			{
				//FrameInc = -FrameInc;
				CurrentFrame = 0;
			}
		//}
		//else
		//{
		//	if(CurrentFrame <= 0)
		//	{
		//		FrameInc = -FrameInc;
		//	}
		//}
	}
	else
	{
		if(CurrentFrame >= MaxFrames)
		{
			CurrentFrame = 0;
		}
	}
}

void GAnimation::SetFrameRate(int Rate)
{
	FrameRate = Rate;
}

void GAnimation::SetCurrentFrame(int Frame)
{
	if(Frame < 0 || Frame >= MaxFrames) 
		return;

	CurrentFrame = Frame;
}

int GAnimation::GetCurrentFrame()
{
	return CurrentFrame;
}